package common;

import java.net.MalformedURLException;
import java.text.SimpleDateFormat ;
import java.util.Collections ;
import java.util.Date ;
import java.util.HashMap ;
import java.util.Map ;

import com.caucho.hessian.client.HessianProxyFactory;

import dicts.RealmDict;
import interfaces.ITransactionService ;
import utils.StringUtil;

public class Service {

	private static HessianProxyFactory factory = new HessianProxyFactory();
	private static String sign = "I";

	public static Object create(Class<?> service) {
		try {
			factory.setOverloadEnabled(true);
			return factory.create(service, RealmDict.RPC + StringUtil.lowerHead(StringUtil.removeStart(service.getSimpleName(), sign)));
		} catch (MalformedURLException e) {
			System.out.println("Hessian Service initial failed " + e.getMessage());
			return null;
		}
	}
	
	public static void main(String[] args) throws Exception{
		
//		IReplaceService r=(IReplaceService) Service.create(IReplaceService.class);
//		
//		Map paramMap=new HashMap();
//		paramMap.put("bnkNo", "WONEDC1001");
//		TReplace rrr=r.dynamic(paramMap);
//		System.out.println(rrr.getRepAddress());
		
//		IGlobalService globalService =(IGlobalService) Service.create(IGlobalService.class);
//		String sql="select * from t_currency";
//		try {
//			
//			QuerySet<Object> querySet = new QuerySet<Object>();
//			querySet.setSqlInfo(sql);
//
//			ResultSet<LinkedHashMap<String, Object>> resultSet=globalService.search(querySet);
//			List<LinkedHashMap<String, Object>> resultList=resultSet.getResultList();
//			System.out.println(resultList);
//		} catch (Exception e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//		
	
		Map<String, Object> paramMap = Collections.synchronizedMap(new HashMap<String, Object>());
		paramMap.put("txnNo", StringUtil.split("3002000001"));
		paramMap.put("crdNumber", "4283428305041009");
		paramMap.put("txnState", "1");
		paramMap.put("txnDate", new Date[] { new SimpleDateFormat("yyyy-MM-dd").parse ( "2019-10-01" )  , new Date() });
		ITransactionService transactionService =(ITransactionService) Service.create(ITransactionService.class);
		boolean c=transactionService.possess(paramMap);
		System.out.println(c);
		
	}
}
